package com.liangjie.application;

import java.io.IOException;
import java.io.PrintWriter;

import javax.servlet.ServletContext;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

public class Application extends HttpServlet {

	private static final long serialVersionUID = 1L;

	@Override
	protected void doGet(HttpServletRequest req, HttpServletResponse resp)
			throws ServletException, IOException {
		PrintWriter pw = resp.getWriter();
		ServletContext application = this.getServletContext();

		Integer accessCount = (Integer) application.getAttribute("accessCount");
		if (accessCount == null) {
			accessCount = new Integer(0);
		} else {
			accessCount = new Integer(accessCount.intValue() + 1);
		}

		application.setAttribute("accessCount", accessCount);

		pw.print(accessCount);
	}

	@Override
	protected void doPost(HttpServletRequest req, HttpServletResponse resp)
			throws ServletException, IOException {
		doGet(req, resp);
	}

}
